# Maintainer: Miloš Komarčević <miloskomarcevic@aim.com>

_realname=libinih
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=57
pkgrel=1
pkgdesc="A simple .INI file parser written in C (mingw-w64)"
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32' 'clangarm64')
url='https://github.com/benhoyt/inih'
license=('spdx:BSD-3-Clause')
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")
makedepends=("${MINGW_PACKAGE_PREFIX}-cc"
             "${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-pkgconf"
             "${MINGW_PACKAGE_PREFIX}-python")
source=("https://github.com/benhoyt/inih/archive/refs/tags/r${pkgver}.tar.gz")
sha256sums=('f03f98ca35c3adb56b2358573c8d3eda319ccd5287243d691e724b7eafa970b3')

build() {
  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/meson.exe setup \
      --prefix="${MINGW_PREFIX}" \
      --wrap-mode=nodownload \
      --auto-features=enabled \
      --buildtype=plain \
      -Ddefault_library=static \
      -Ddistro_install=true \
      -Dwith_INIReader=true \
      "build-${MSYSTEM}-static" \
      "inih-r${pkgver}"

  ${MINGW_PREFIX}/bin/meson.exe compile -C "build-${MSYSTEM}-static"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/meson.exe setup \
      --prefix="${MINGW_PREFIX}" \
      --wrap-mode=nodownload \
      --auto-features=enabled \
      --buildtype=plain \
      -Ddefault_library=shared \
      -Ddistro_install=true \
      -Dwith_INIReader=true \
      "build-${MSYSTEM}-shared" \
      "inih-r${pkgver}"

  ${MINGW_PREFIX}/bin/meson.exe compile -C "build-${MSYSTEM}-shared"
}

package() {
  ${MINGW_PREFIX}/bin/meson.exe install --destdir "${pkgdir}" -C "build-${MSYSTEM}-static"
  ${MINGW_PREFIX}/bin/meson.exe install --destdir "${pkgdir}" -C "build-${MSYSTEM}-shared"

  install -Dm644 "${srcdir}/inih-r${pkgver}/LICENSE.txt" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
